package com.lemo.shiro.realms;

import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.LockedAccountException;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.realm.AuthenticatingRealm;

public class RealmOne extends AuthenticatingRealm {

	@Override
	protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken auToken) throws AuthenticationException {

		System.out.println(auToken);

		UsernamePasswordToken token = (UsernamePasswordToken) auToken;
		String username = token.getUsername();

		if ("lee".equals(username)) {
			System.out.println("用户不存在！");
			throw new UnknownAccountException("用户不存在");
		}
		if ("lemo".equals(username)) {
			throw new LockedAccountException("锁户");
		}
		Object principal = username;
		Object credentials = "123456";
		String realmName = getName();
		SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(principal, credentials, realmName);
		return info;
	}

}
